package com.antaohua.tools.shares.dao;

import org.springframework.stereotype.Repository;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.antaohua.tools.framework.base.dao.BaseDao;
import com.antaohua.tools.shares.entity.SharesStockIndexEntity;

@Repository
public class SharesStockIndexDao extends BaseDao<SharesStockIndexEntity>{

	@Override
	protected Class<SharesStockIndexEntity> getEntityClass() {
		return SharesStockIndexEntity.class;
	}

	public static void main(String[] args) {
		String  a = "{\"showapi_res_code\":0,\"showapi_res_error\":\"\",\"showapi_res_body\":{\"ret_code\":0,\"indexList\":[{\"yestodayClosePrice\":\"3152.1869\",\"todayMax\":\"3154.7266\",\"todayMin\":\"3136.5781\",\"max52\":\"0\",\"diff_money\":\"2.47\",\"tradeNum\":\"16288989900\",\"code\":\"sh000001\",\"maxPrice\":\"3154.7266\",\"nowPrice\":\"3154.6584\",\"min52\":\"0\",\"time\":\"2017-04-28 15:02:03\",\"name\":\"上证指数\",\"tradeAmount\":\"183195769806\",\"swing\":\"0.58\",\"todayOpenPrice\":\"3144.0219\",\"diff_rate\":\"0.08\",\"minPrice\":\"3136.5781\"},{\"yestodayClosePrice\":\"10229.194\",\"todayMax\":\"10235.228\",\"todayMin\":\"10176.082\",\"max52\":\"0\",\"diff_money\":\"5.46\",\"tradeNum\":\"16449884003\",\"code\":\"sz399001\",\"maxPrice\":\"10235.228\",\"nowPrice\":\"10234.652\",\"min52\":\"0\",\"time\":\"2017-04-28 16:35:03\",\"name\":\"深证成指\",\"tradeAmount\":\"233285853539.021\",\"swing\":\"0.58\",\"todayOpenPrice\":\"10208.133\",\"diff_rate\":\"0.05\",\"minPrice\":\"10176.082\"},{\"yestodayClosePrice\":\"6642.047\",\"todayMax\":\"6643.708\",\"todayMin\":\"6593.568\",\"max52\":\"0\",\"diff_money\":\"-1.87\",\"tradeNum\":\"1307457244\",\"code\":\"sz399005\",\"maxPrice\":\"6643.708\",\"nowPrice\":\"6640.181\",\"min52\":\"0\",\"time\":\"2017-04-28 16:35:03\",\"name\":\"中小板指\",\"tradeAmount\":\"23857110416.190\",\"swing\":\"0.75\",\"todayOpenPrice\":\"6620.746\",\"diff_rate\":\"-0.03\",\"minPrice\":\"6593.568\"},{\"yestodayClosePrice\":\"1842.922\",\"todayMax\":\"1856.403\",\"todayMin\":\"1834.426\",\"max52\":\"0\",\"diff_money\":\"7.81\",\"tradeNum\":\"1028837867\",\"code\":\"sz399006\",\"maxPrice\":\"1856.403\",\"nowPrice\":\"1850.734\",\"min52\":\"0\",\"time\":\"2017-04-28 16:35:03\",\"name\":\"创业板指\",\"tradeAmount\":\"17893027512.200\",\"swing\":\"1.19\",\"todayOpenPrice\":\"1838.744\",\"diff_rate\":\"0.42\",\"minPrice\":\"1834.426\"},{\"yestodayClosePrice\":\"24698.480\",\"todayMax\":\"24697.031\",\"todayMin\":\"24563.770\",\"max52\":\"24717.439\",\"diff_money\":\"-83.35\",\"tradeNum\":\"\",\"code\":\"hkHSI\",\"maxPrice\":\"24697.031\",\"nowPrice\":\"24615.129\",\"min52\":\"19594.609\",\"time\":\"2017-04-28 16:09:40\",\"name\":\"恒生指数\",\"tradeAmount\":\"65396726988\",\"swing\":\"0.54\",\"todayOpenPrice\":\"24691.289\",\"diff_rate\":\"-0.34\",\"minPrice\":\"24563.770\"}]}}";
		
		JSONObject json = JSON.parseObject(a);
		JSONArray array = json.getJSONObject("showapi_res_body").getJSONArray("indexList");
		for(int i=0;i<array.size();i++){
			SharesStockIndexEntity aaaa = array.getObject(i, SharesStockIndexEntity.class);
			System.out.println(aaaa.getName());
			System.out.println(aaaa.getId());
		}
	}
}
